package com.zzptc.myapp1130bookreader.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.zzptc.myapp1130bookreader.Bean.Book;
import com.zzptc.myapp1130bookreader.R;

import java.util.List;


public class BookAdapter extends ArrayAdapter<Book> {
    private int resourceid;

    public BookAdapter(@NonNull Context context, int resource, @NonNull List<Book> objects) {
        super(context, resource, objects);
        this.resourceid=resource;

    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceid, null);
        }
        ImageView bookimg = view.findViewById(R.id.bookimg);
        TextView bookname = view.findViewById(R.id.bookname);
        TextView authorname = view.findViewById(R.id.authorname);

        Book b=getItem(position);
        bookimg.setImageResource(b.getBookimg());
        bookname.setText(b.getBookname());
        authorname.setText("作者:"+b.getAuthorname());


        return view;

    }
}
